<script>
export default {
name: "AddGoods",
  methods: {
    submitHandler(){
      const goodsName= this.$refs.goodsName.value.trim();
      const goodsPrice= this.$refs.goodsPrice.value.trim();
      if(goodsName.length>0 && goodsPrice.length>0){
        this.$store.commit('ADD_Goods', {goodsName, goodsPrice});
      }else{
        alert("请输入");
      }
      this.$refs.goodsName.value=null;
      this.$refs.goodsPrice.value=null;
    }
  }
}
</script>

<template>
  <form>
    <p>商品名称: <input ref="goodsName" type="text"> </p>
    <p>商品价格: <input ref="goodsPrice" type="text"> </p>
    <button @click.prevent="submitHandler">提交</button>
  </form>
</template>

<style scoped>

</style>